import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'ink_widget.dart';

/// todo：tab菜单
tab({
  List<String>? tabs,
  int currentIndex:0,
  Function(int)? onTap,
  double? width,
  MainAxisAlignment? mainAxisAlignment,
  Color? bgColor,
  EdgeInsetsGeometry? padding,
  double? height,
}){
  return Container(
    width: Get.width,
    height: height,
    padding: padding ?? EdgeInsets.symmetric(vertical: 10,horizontal: 15),
    color: bgColor,
    child: tabs!.length < 6 ? Row(
      mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: _item(tabs,currentIndex,onTap),
    ) : ListView(
        padding: EdgeInsets.all(0),
        scrollDirection: Axis.horizontal,
        children:  _item(tabs,currentIndex,onTap),
    ),
  );

}

_item(tabs,currentIndex,onTap){
  return List.generate(tabs.length, (index){
    return Material(
      color: Colors.transparent,
      child: InkWell(
        child: Container(
          padding: EdgeInsets.only(right: 15),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              InkWidget.text("${tabs[index]}",fonSize: 18,color: currentIndex == index ? Colors.black : Colors.grey),
              Container(
                color: currentIndex == index ? Colors.green : Colors.transparent,
                height: 5,
                child: InkWidget.title("${tabs[index]}",fonSize: 18,color: Colors.transparent),
              ),
            ],
          ),
        ),
        onTap: (){
          onTap!(index);
        },
      ),
    );
  });
}